package com.xzr.test;

import com.xzr.spring.MultitonFactory;
import com.xzr.spring.MultitonFactory2;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;

public class Day01 {
    public static void main(String[] args) {
//        FirstFactory firstFactory = new FirstFactory();
//        Person person = (Person) firstFactory.doPerson("美国人");
//        person.eat();


//        SecondFactory secondFactory = new SecondFactory();
//        Person person = (Person) secondFactory.doPerson("American");
//        person.eat();

//        FourthFactory fourthFactory = new FourthFactory();
//        Person person = fourthFactory.doPerson();
//        person.eat();


//        BeanFactory factory = new BeanFactory();
//        Person person = factory.getBean("american");
//        person.eat();

        //多例测试
        MultitonFactory multitonFactory = new MultitonFactory();
        Person chinese = multitonFactory.getBean("chinese");
        Person chinese1 = multitonFactory.getBean("chinese");
        System.out.println(chinese);
        System.out.println(chinese1);
        chinese.eat();

        System.out.println("-------------------------------------");
        MultitonFactory2 multitonFactory2 = new MultitonFactory2();
        Person c1 = multitonFactory2.getBean("chinese");
        Person c2 = multitonFactory2.getBean("chinese");
        System.out.println(c1);
        System.out.println(c2);
        c1.eat();

        System.out.println("-------------------------------------");
        //spring测试
        BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
        Person person = (Person) beanFactory.getBean("chinese");
        Person person1 = (Person) beanFactory.getBean("american");
        person.eat();
        person1.eat();
    }
}
